Let’s get started with some hands-on exercises and exploring some data! This exercise focuses on importing different vector data geometries from various data sources and getting used to simple feature data tables.
In the folder ./data, you can find the data files prepped for all the exercises which rely on preexisting data sets. However, if you like to play around with your own data, feel free to do so! .
Load the administrative borders of Germany. Therefore, import the shapefile VG250_STA.shp from the respective folder and assign it to an object named “germany”.
sf and set your working directory before starting this exercise.
library(sf)
germany <- sf::read_sf("./data/VG250_STA.shp")
plot(germany)
## Warning: plotting the first 10 out of 23 attributes; use max.plot = 23 to plot all
The output in the console of `R gives you already some information on the data you just loaded. You also see that the object “germany” appeared in your environment. Though, we will explore the data set a little bit closer.
Explore the data and answer the following questions:
sf::st_geometry(germany) # Multipolygon: Set of several Polygons. Each row is a polygon.
## Geometry set for 11 features
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: 280371.1 ymin: 5235856 xmax: 921292.4 ymax: 6106244
## Projected CRS: ETRS89 / UTM zone 32N
## First 5 geometries:
## MULTIPOLYGON (((609387.6 5267931, 609423.3 5267...
## MULTIPOLYGON (((492810 6029412, 492821.2 602927...
## MULTIPOLYGON (((816809.9 5978628, 816854.5 5978...
## MULTIPOLYGON (((502125 5972301, 502668.3 597211...
## MULTIPOLYGON (((500425.1 5285873, 500485.1 5285...
class(germany) # "sf", "tbl_df", "tbl" and "data.frame"
## [1] "sf" "tbl_df" "tbl" "data.frame"
attr(germany, "sf_column") # geometry
## [1] "geometry"
sf::st_crs(germany) # ETRS89, ID = EPSG:4258
## Coordinate Reference System:
## User input: ETRS89 / UTM zone 32N
## wkt:
## PROJCRS["ETRS89 / UTM zone 32N",
## BASEGEOGCRS["ETRS89",
## DATUM["European Terrestrial Reference System 1989",
## ELLIPSOID["GRS 1980",6378137,298.257222101,
## LENGTHUNIT["metre",1]]],
## PRIMEM["Greenwich",0,
## ANGLEUNIT["degree",0.0174532925199433]],
## ID["EPSG",4258]],
## CONVERSION["UTM zone 32N",
## METHOD["Transverse Mercator",
## ID["EPSG",9807]],
## PARAMETER["Latitude of natural origin",0,
## ANGLEUNIT["degree",0.0174532925199433],
## ID["EPSG",8801]],
## PARAMETER["Longitude of natural origin",9,
## ANGLEUNIT["degree",0.0174532925199433],
## ID["EPSG",8802]],
## PARAMETER["Scale factor at natural origin",0.9996,
## SCALEUNIT["unity",1],
## ID["EPSG",8805]],
## PARAMETER["False easting",500000,
## LENGTHUNIT["metre",1],
## ID["EPSG",8806]],
## PARAMETER["False northing",0,
## LENGTHUNIT["metre",1],
## ID["EPSG",8807]]],
## CS[Cartesian,2],
## AXIS["(E)",east,
## ORDER[1],
## LENGTHUNIT["metre",1]],
## AXIS["(N)",north,
## ORDER[2],
## LENGTHUNIT["metre",1]],
## USAGE[
## SCOPE["Engineering survey, topographic mapping."],
## AREA["Europe between 6°E and 12°E: Austria; Belgium; Denmark - onshore and offshore; Germany - onshore and offshore; Norway including - onshore and offshore; Spain - offshore."],
## BBOX[38.76,6,83.92,12]],
## ID["EPSG",25832]]
names(germany) # Name, Area Type, Area Size, Population Size
## [1] "ADE" "GF" "BSG" "ARS" "AGS" "SDV_ARS" "GEN" "BEZ" "IBZ"
## [10] "BEM" "NBD" "SN_L" "SN_R" "SN_K" "SN_V1" "SN_V2" "SN_G" "FK_S3"
## [19] "NUTS" "ARS_0" "AGS_0" "WSK" "DEBKG_ID" "geometry"
GF == 4.
# It seems like the shapefile contains not only the land area of Germany but also coastal areas and lakes.
# filter
germany_new <-
germany %>%
dplyr::filter(GF == 4)
germany_new
## Simple feature collection with 1 feature and 23 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: 280371.1 ymin: 5235856 xmax: 921292.4 ymax: 6101487
## Projected CRS: ETRS89 / UTM zone 32N
## # A tibble: 1 × 24
## ADE GF BSG ARS AGS SDV_ARS GEN BEZ IBZ BEM NBD SN_L SN_R SN_K SN_V1 SN_V2 SN_G FK_S3
## * <int> <int> <int> <chr> <chr> <chr> <chr> <chr> <int> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 1 4 1 000000… 0000… 110000… Deut… Bund… 10 -- ja 00 0 00 00 00 000 0
## # … with 6 more variables: NUTS <chr>, ARS_0 <chr>, AGS_0 <chr>, WSK <date>, DEBKG_ID <chr>,
## # geometry <MULTIPOLYGON [m]>